import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.sql.*;


public class EmpProfileForm extends JPanel{
	private static final long serialVersionUID = 1L;
	private  ImageIcon proH = new ImageIcon(this.getClass().getResource("images/header/prof.png"));
	JButton editP;
	JLabel prof, uslabel, fullabel, blabel, adlabel, clabel, userid, slabel, fullname, bDate, cnum, status;
	private JTextArea address;
	
	Connection conn = null;

	public EmpProfileForm(){
		
		prof = new JLabel(proH);
		prof.setBounds(135, 35, proH.getIconWidth(), proH.getIconHeight());
		prof.setVisible(true);
		
		editP = new JButton("Edit Profile");
		editP.setBounds (555, 110, 100, 25);
		editP.setVisible(true);
		editP.setForeground(Color.WHITE);
		editP.setBackground(Color.BLACK);
		
		//construct components
	    uslabel = new JLabel ("UserID:");
	    fullabel = new JLabel ("Full name:");
	    blabel = new JLabel ("Birthdate:");
	    adlabel = new JLabel ("Address:");
	    clabel = new JLabel ("Contact no.:");
	    userid = new JLabel ("newLabel");
	    slabel = new JLabel ("Status:");
	    address = new JTextArea (5, 5);
	    fullname = new JLabel ("");
	    bDate = new JLabel ("");
	    cnum = new JLabel ("");
	    status = new JLabel ("");
	    
	    uslabel.setBounds (150, 105, 50, 25);
	    fullabel.setBounds (150, 130, 75, 25);
	    blabel.setBounds (150, 155, 70, 25);
	    adlabel.setBounds (150, 180, 65, 25);
	    clabel.setBounds (150, 265, 80, 25); 
	    slabel.setBounds (150, 290, 55, 25);
	    userid.setBounds (195, 105, 100, 25);
	    address.setBounds (210, 185, 175, 75);
	    fullname.setBounds (210, 130, 150, 25);
	    bDate.setBounds (210, 155, 135, 25);
	    cnum.setBounds (225, 265, 115, 25);
	    status.setBounds (195, 290, 110, 25);
	    

		add(prof);
		add(editP);
		add (uslabel);
	    add (fullabel);
	    add (blabel);
	    add (adlabel);
	    add (clabel);
	    add (userid);
	    add (slabel);
	    add (address);
	    add (fullname);
 	    add (bDate);
	    add (cnum);
	    add (status);		
		
		setLayout(null);
		setOpaque(false);
		setSize(806,628);
		setVisible(true);
	
		editP.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				EditEmpForm eEdit = new EditEmpForm();
				eEdit.setVisible(true);
				eEdit.pack();
				
			}
		});

		
	}
	
	public void profileUpdate(){

		try
			{
			ConnectionFactory myFactory = ConnectionFactory.getFactory();
	        Connection conn = myFactory.getConnection();
	    	Statement stat = conn.createStatement(); 
	        ResultSet res = stat.executeQuery("SELECT concat(firstName, ' ', middleInitial, ' ', lastName) as 'Full Name', contactNum," +
	        		"DATE_FORMAT(bDate,'%M %e, %Y') as 'Birthdate', address, status FROM bernalcompany.employee WHERE idemployee ='"+MainPanel.getUID()+"'");//'"+ UserPrompt.getID() + "'");
		   
	        if(res.next()){
		    	
		    address.setLineWrap(true);
		    address.setText(res.getString("address"));
		    address.setWrapStyleWord(true);
		    fullname.setText(res.getString("Full Name"));
		    userid.setText(String.valueOf(MainPanel.getUID()));
		    bDate.setText(res.getString("Birthdate"));
		    cnum.setText(res.getString("contactNum"));
		    status.setText(res.getString("status"));
		    address.setEditable(false);
			}
			else
				System.out.println("di gumana :(");
			
		    conn.close();
	    
		}catch(Exception ex){
			ex.printStackTrace();
		}

	}
	
}

